simple_upgrade_example.js ➔ getWallet   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
nop 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A simple_upgrade_example.js ➔ ... ➔ client.then-1 0 10 2
A simple_upgrade_example.js ➔ ... ➔ client.then-0 0 3 1
A simple_upgrade_example.js ➔ ... ➔ client.progress 0 3 1
1
var blocktrail = require('../'); // require('blocktrail-sdk') when trying example from in your own project
2
3
var client = blocktrail.BlocktrailSDK({
4
    apiKey: process.env.BLOCKTRAIL_SDK_APIKEY || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APIKEY",
5
    apiSecret: process.env.BLOCKTRAIL_SDK_APISECRET || "EXAMPLE_BLOCKTRAIL_SDK_NODEJS_APISECRET",
6
    testnet: true
7
});
8
9
var randi = (Math.random() * 10000).toFixed();
10
11
var passphrase = "example-strong-password";
12
var walletVersion = blocktrail.Wallet.WALLET_VERSION_V2;
13
var identifier = "example-wallet-" + randi;
14
15
console.log("identifier: " + identifier);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
16
17
var getWallet = function() {
18
    return client.createNewWallet({
19
        identifier: identifier,
20
        passphrase: passphrase,
21
        walletVersion: walletVersion,
22
        keyIndex: 9999
23
    })
24
        .progress(function(p) {
25
            console.log('progress', p);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
26
        })
27
        .then(function(r) {
28
            return r[0];
29
        }, function(e) {
30
            if (e.message.match(/already exists/)) {
31
                return client.initWallet({
32
                    identifier: identifier,
33
                    passphrase: passphrase
34
                });
35
            } else {
36
                throw e;
37
            }
38
        });
39
};
40
41
getWallet()
42
    .then(function(wallet) {
43
        console.log('got wallet');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
44
        console.log(wallet.getAddressByPath("M/9999'/0/0"));
45
46
        return wallet;
47
    })
48
    .then(function(wallet) {
49
        return wallet.upgradeToV3(passphrase)
50
            .then(function() {
51
                return wallet;
52
            });
53
    })
54
    .then(function(wallet) {
55
        console.log('UPGRADED!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
56
57
        console.log(wallet.getAddressByPath("M/9999'/0/0"));
58
    })
59
    .catch(function(e) {
60
        console.log(e);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
61
        throw e;
62
    })
63
    .done();
64